%Figure 2
%Comparative Statics in effort for different levels of alpha


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% KAPPA %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%


clear all; close all;
para; 

%Note: We choose an extremely fine grid for q. This makes the execution
%slow. You can obtain less accurate but faster results for a lower value of
%qGrid; inaccuracies mainly occur for very large values of kappa and are
%mostly cosmetic. 
qGrid=600;
iComp=40;
%To speed up computation, choose lower iComp


kappaSpace=linspace(7,50,iComp);

for comp=1:iComp
    
    kappa=kappaSpace(comp);
    
    %Solve model for alpha=0
    OptContract;
    SB;
    Solve;
    
    vA0(comp)=a0;
    vQ(comp)=q;
    
    %Solve model for negative alpha=-2
    clear sol vA;
    alpha=alphaNeg1;
    SolutionAlpha;

    vA0Neg(comp)=a0;
    vQNeg(comp)=q;

    %Solve model for negative alpha=-1

    clear sol vA;
    alpha=alphaNeg2;
    SolutionAlpha;

    vA0Pos(comp)=a0;
    vQPos(comp)=q;
    
    
    
    
end 
%Plot against kappa grid
space=kappaSpace;


subplot(2,4,1); hold on
 plot(space,smooth(vA0), 'k', 'Linewidth',3);
  plot(space,smooth(vA0Pos), 'r:', 'Linewidth',3);
 plot(space,smooth(vA0Neg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\kappa$','Interpreter','latex')
 ylabel('$a_0$','Interpreter','latex')
 title('A: Monitoring ($\kappa$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;

 subplot(2,4,5); hold on
 plot(space,smooth(vQ), 'k', 'Linewidth',3);
  plot(space,smooth(vQPos), 'r:', 'Linewidth',3);
 plot(space,smooth(vQNeg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\kappa$','Interpreter','latex')
 ylabel('$q$','Interpreter','latex')
 title('E: Screening ($\kappa$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;


 %%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%% PHI %%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%
%Analogous to above; comparaitive statics wrt phi
clear all; 
para; 
%Note: We choose an extremely fine grid for q. This makes the execution
%slow. You can obtain less accurate but faster results for a lower value of
%qGrid; inaccuracies mainly occur for very large values of phi and are
%mostly cosmetic. 
qGrid=600;
iComp=20;
phiSpace=linspace(7,50,iComp);



for comp=1:iComp
    
    phi=phiSpace(comp);
 
    OptContract;
    SB;
    Solve;
    
    vA0(comp)=a0;
    vQ(comp)=q;
    

    clear sol vA;
    alpha=alphaNeg1;
    SolutionAlpha;

    vA0Neg(comp)=a0;
    vQNeg(comp)=q;


    clear sol vA;
    alpha=alphaNeg2;
    SolutionAlpha;

    vA0Pos(comp)=a0;
    vQPos(comp)=q;
    
  
    
    
end 

space=phiSpace;
fFigure=figure(1); hold on;


subplot(2,4,2); hold on
 plot(space,smooth(vA0), 'k', 'Linewidth',3);
  plot(space,smooth(vA0Pos), 'r:', 'Linewidth',3);
 plot(space,smooth(vA0Neg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\phi$','Interpreter','latex')
 ylabel('$a_0$','Interpreter','latex')
 title('B: Monitoring ($\phi$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;

 subplot(2,4,6); hold on
 plot(space,smooth(vQ), 'k', 'Linewidth',3);
  plot(space,smooth(vQPos), 'r:', 'Linewidth',3);
 plot(space,smooth(vQNeg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\phi$','Interpreter','latex')
 ylabel('$q$','Interpreter','latex')
 title('F: Screening ($\phi$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;



 %%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%% Lambda %%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%
%Analogous to above; comparaitive statics wrt Lambda
%It suffices to use qGrid=100

clear all; 
para; 

qGrid=100;
iComp=20;
LambdaSpace=linspace(0.95,1.1,iComp);



for comp=1:iComp
    
    Lambda=LambdaSpace(comp);
 
    OptContract;
    SB;
    Solve;
    
    vA0(comp)=a0;
    vQ(comp)=q;
    

    clear sol vA;
    alpha=alphaNeg1;
    SolutionAlpha;

    vA0Neg(comp)=a0;
    vQNeg(comp)=q;


    clear sol vA;
    alpha=alphaNeg2;
    SolutionAlpha;

    vA0Pos(comp)=a0;
    vQPos(comp)=q;
    
  
    
    
end 

space=LambdaSpace;
fFigure=figure(1); hold on;


subplot(2,4,3); hold on
 plot(space,smooth(vA0), 'k', 'Linewidth',3);
  plot(space,smooth(vA0Pos), 'r:', 'Linewidth',3);
 plot(space,smooth(vA0Neg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\Lambda$','Interpreter','latex')
 ylabel('$a_0$','Interpreter','latex')
 title('C: Monitoring ($\Lambda$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;

 subplot(2,4,7); hold on
 plot(space,smooth(vQ), 'k', 'Linewidth',3);
  plot(space,smooth(vQPos), 'r:', 'Linewidth',3);
 plot(space,smooth(vQNeg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\Lambda$','Interpreter','latex')
 ylabel('$q$','Interpreter','latex')
 title('G: Screening ($\Lambda$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;


  %%%%%%%%%%%%%%%%%%%%%%%%%%
 %%%%%% Gamma %%%%%%%%%%%%%%
 %%%%%%%%%%%%%%%%%%%%%%%%%
%Analogous to above; comparaitive statics wrt gamma
%We use the value of qGrid from para.m
clear all; 
para; 
iComp=20;
gammaSpace=linspace(0.05,0.15,iComp);



for comp=1:iComp
    
    gamma=gammaSpace(comp);
 
    OptContract;
    SB;
    Solve;
    
    vA0(comp)=a0;
    vQ(comp)=q;
    

    clear sol vA;
    alpha=alphaNeg1;
    SolutionAlpha;

    vA0Neg(comp)=a0;
    vQNeg(comp)=q;


    clear sol vA;
    alpha=alphaNeg2;
    SolutionAlpha;

    vA0Pos(comp)=a0;
    vQPos(comp)=q;
    
  
    
    
end 

space=gammaSpace;
fFigure=figure(1); hold on;


subplot(2,4,4); hold on
 plot(space,smooth(vA0), 'k', 'Linewidth',3);
  plot(space,smooth(vA0Pos), 'r:', 'Linewidth',3);
 plot(space,smooth(vA0Neg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\gamma$','Interpreter','latex')
 ylabel('$a_0$','Interpreter','latex')
 title('C: Monitoring ($\gamma$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;

 subplot(2,4,8); hold on
 plot(space,smooth(vQ), 'k', 'Linewidth',3);
  plot(space,smooth(vQPos), 'r:', 'Linewidth',3);
 plot(space,smooth(vQNeg), '-.', 'Linewidth',3);
 leg2=legend('$\alpha=0$','$\alpha=-1$', '$\alpha=-2$','Location','best'  ) ;
 set(leg2,'Interpreter','latex','FontSize',13);
 xlabel('$\gamma$','Interpreter','latex')
 ylabel('$q$','Interpreter','latex')
 title('F: Screening ($\gamma$)','Interpreter', 'LaTex', 'FontSize',13)
 axis tight;
 


 

 resize_plot(fFigure,12,5.5,13);
print('CompStatEffortAlpha','-depsc')
%print('CompStatEffortAlphaDelta','-depsc')

